process.env.NODE_ENV = 'production'
const merge = require('webpack-merge')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const TerserJSPlugin = require('terser-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const commonConfig = require('./webpack.common.js')
/**
 * @type { import('webpack').Configuration }
 */
module.exports = merge(commonConfig, {
    mode: 'production',
    devtool: 'none',
    output: {
        filename: 'js/[name].[chunkhash].js',
        chunkFilename: 'js/[id].[chunkhash].js'
    },
    optimization: {
        minimizer: [ new TerserJSPlugin(), new OptimizeCSSAssetsPlugin()]
    },  
    plugins: [
        new CleanWebpackPlugin(),
        new CopyWebpackPlugin({
            patterns: [
                { from: 'public' },
            ],
        }),
        // new BundleAnalyzerPlugin(),
        new MiniCssExtractPlugin(
            {
                filename: 'css/[name].[contenthash:6].css',
            }
        )
    ]
})